package system

import (
	"github.com/astaxie/beego"
	"monitor_agent/apps/base"
	"monitor_agent/apps/cpu"
	"monitor_agent/apps/filesystems"
	"monitor_agent/apps/memory"
	"monitor_agent/apps/net"
	"monitor_agent/apps/processes"
)

func init() {
	beego.Router("/system/overview", &Controller{}, "GET:OverView")
	beego.Router("/system/info", &Controller{}, "GET:Info")
}

type Controller struct {
	base.Controller
}

func (o *Controller) Info() {
	info := map[string]interface{}{
		"cpu_count":   cpu.Count(),
		"memory_size": memory.TotalSize(),
		"root_size":   filesystems.RootSize(),
		"data_size":   filesystems.DataSize(),
	}
	o.Data["json"] = info
	o.ServeJSON()
}

func (o *Controller) OverView() {
	o.Data["json"] = map[string]interface{}{
		"cpu":            cpu.Register.GetAll(),
		"memory":         memory.Register.GetAll(),
		"net":            net.Register.GetAll(),
		"disk":           filesystems.Register.GetAll(),
		"system":         Register.GetAll(),
		"process_status": processes.Register.GetAll(),
	}
	o.ServeJSON()
}
